﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using Gift.DBUtility;//请先添加引用
using Gift.Model;
namespace Gift.DAL
{
   public class DALGoodsScore
    {
        // Methods
        public bool AddGoodsScore(tbGoodsScore GoodsScore)
        {
            bool flag = false;
            try
            {
                string commandText = string.Format("insert into tbGoodsScore(UserId,ProId,scores) values(@UserId,@ProId,@scores)", new object[0]);
                SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@UserId", GoodsScore.UserId), new SqlParameter("@ProId", GoodsScore.ProId), new SqlParameter("@scores", GoodsScore.Scores) };
                if (DbHelperSQL.ExecuteSql(commandText, parameters) > 0)
                {
                    flag = true;
                }
            }
            catch
            {
            }
            return flag;
        }

        public DataTable GetGoodsScoreByGoods(int iProId)
        {
            DataTable table = new DataTable();
            try
            {
                string commandText = string.Format("select (select count(*) from tbGoodsScore where ProId=@ProId) as scoresNumber,Convert(decimal(10,1),(Convert(decimal(10,1),(select sum(scores) from tbGoodsScore where ProId=@ProId)))/(select count(*) from tbGoodsScore where ProId=@ProId)) as scores", new object[0]);
                SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@ProId", iProId) };
                table = DbHelperSQL.Query(commandText, parameters).Tables[0];
            }
            catch
            {
            }
            return table;
        }

    }
}
